/**
 * @(#)ProcessLogVO.java Aug 31, 2009
 *   
 * Copyright  (c) 2009-2010 Wilmar IT Service,  Inc.   
 * All  rights  reserved.   
 * TODO
 */

package com.wilmar.process.entity.vo;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.List;

import com.wilmar.process.core.ProcessSystemDeclareKeys;
import com.wilmar.process.entity.Attachement;
import com.wilmar.process.entity.ProcessLog;
import com.wilmar.process.entity.comparator.AttachementComparator;
import com.wilmar.process.enumerate.EnumProcessLogLevel;
import com.wilmar.process.enumerate.EnumProcessOperateOpinionType;

/**
 * @author MaKuBEX Email:makubexnet@gmail.com
 * @version 1.0.0
 */
public class ProcessLogVO extends AbstractValueObject {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 8030211517014605518L;

	private Long id;
	private String processInstanceId;
	private String enterTime;
	private String leaveTime;
	private String operator;
	private String operatorName;
	private String instanceStarter;
	private String outerSystem;
	private EnumProcessOperateOpinionType opinionType;
	private Integer version;
	private String opinionString;
	private String nodeName;
	private String nodeDesc;
	private String processDefinitionId;
	private String processDefinitionName;
	private String processDesc;
	private String outCome;
	private EnumProcessLogLevel logLevel;
	private List<Attachement> attachements;

	public ProcessLogVO(ProcessLog processLog) {
		SimpleDateFormat sdf = new SimpleDateFormat(
				ProcessSystemDeclareKeys.SYSTEM_LONG_DATE_FORMAT
						+ ProcessSystemDeclareKeys.SPACE
						+ ProcessSystemDeclareKeys.SYSTEM_LONG_TIME_FORMAT);
		this.id = processLog.getId();
		this.processInstanceId = processLog.getProcessInstanceId();
		if (processLog.getEnterTime() != null)
			this.enterTime = sdf.format(processLog.getEnterTime());
		else
			this.enterTime = "";
		if (processLog.getLeaveTime() != null)
			this.leaveTime = sdf.format(processLog.getLeaveTime());
		else
			this.leaveTime = "";
		this.operator = processLog.getOperator();
		if (processLog.getOperatorName() != null)
			this.operatorName = processLog.getOperatorName();
		else
			this.operatorName = "";
		this.version = processLog.getVersion();
		this.opinionString = processLog.getOpinionString();
		if (processLog.getNodeDesc() != null)
			this.nodeDesc = processLog.getNodeDesc();
		else
			this.nodeDesc = "";
		if (processLog.getNodeName() != null)
			this.nodeName = processLog.getNodeName();
		else
			this.nodeName = "";
		if (processLog.getOutCome() != null)
			this.outCome = processLog.getOutCome();
		else
			this.outCome = "";
		this.logLevel = processLog.getLogLevel();
		this.outerSystem = processLog.getOuterSystem();
		this.opinionType = processLog.getOpinionType();
		this.instanceStarter = processLog.getInstanceStarter();
		this.processDefinitionName = processLog.getProcessDefinitionName();
		this.processDesc = "";
	}

	public ProcessLogVO(ProcessLog processLog, List<Attachement> attachementList) {
		SimpleDateFormat sdf = new SimpleDateFormat(
				ProcessSystemDeclareKeys.SYSTEM_LONG_DATE_FORMAT
						+ ProcessSystemDeclareKeys.SPACE
						+ ProcessSystemDeclareKeys.SYSTEM_LONG_TIME_FORMAT);
		this.id = processLog.getId();
		this.processInstanceId = processLog.getProcessInstanceId();
		if (processLog.getEnterTime() != null)
			this.enterTime = sdf.format(processLog.getEnterTime());
		else
			this.enterTime = "";
		if (processLog.getLeaveTime() != null)
			this.leaveTime = sdf.format(processLog.getLeaveTime());
		else
			this.leaveTime = "";
		this.operator = processLog.getOperator();
		if (processLog.getOperatorName() != null)
			this.operatorName = processLog.getOperatorName();
		else
			this.operatorName = "";
		this.version = processLog.getVersion();
		this.opinionString = processLog.getOpinionString();
		if (processLog.getNodeDesc() != null)
			this.nodeDesc = processLog.getNodeDesc();
		else
			this.nodeDesc = "";
		if (processLog.getNodeName() != null)
			this.nodeName = processLog.getNodeName();
		else
			this.nodeName = "";
		if (processLog.getOutCome() != null)
			this.outCome = processLog.getOutCome();
		else
			this.outCome = "";
		this.logLevel = processLog.getLogLevel();
		this.outerSystem = processLog.getOuterSystem();
		this.opinionType = processLog.getOpinionType();
		this.instanceStarter = processLog.getInstanceStarter();
		this.processDefinitionName = processLog.getProcessDefinitionName();
		this.processDesc = "";
		this.attachements = attachementList;
		if (this.attachements != null)
			Collections.sort(this.attachements, new AttachementComparator());
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProcessLogVO other = (ProcessLogVO) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public String getEnterTime() {
		return enterTime;
	}

	public Long getId() {
		return id;
	}

	public String getInstanceStarter() {
		return instanceStarter;
	}

	public String getLeaveTime() {
		return leaveTime;
	}

	public String getNodeDesc() {
		return nodeDesc;
	}

	public String getNodeName() {
		return nodeName;
	}

	public String getOperator() {
		return operator;
	}

	public String getOpinionString() {
		return opinionString;
	}

	public EnumProcessOperateOpinionType getOpinionType() {
		return opinionType;
	}

	public String getOuterSystem() {
		return outerSystem;
	}

	public String getProcessDefinitionId() {
		return processDefinitionId;
	}

	public String getProcessDesc() {
		return processDesc;
	}

	public String getProcessInstanceId() {
		return processInstanceId;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	/**
	 * @return the logLevel
	 */
	public EnumProcessLogLevel getLogLevel() {
		return logLevel;
	}

	/**
	 * @param logLevel
	 *            the logLevel to set
	 */
	public void setLogLevel(EnumProcessLogLevel logLevel) {
		this.logLevel = logLevel;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param processInstanceId
	 *            the processInstanceId to set
	 */
	public void setProcessInstanceId(String processInstanceId) {
		this.processInstanceId = processInstanceId;
	}

	/**
	 * @param enterTime
	 *            the enterTime to set
	 */
	public void setEnterTime(String enterTime) {
		this.enterTime = enterTime;
	}

	/**
	 * @param leaveTime
	 *            the leaveTime to set
	 */
	public void setLeaveTime(String leaveTime) {
		this.leaveTime = leaveTime;
	}

	/**
	 * @param operator
	 *            the operator to set
	 */
	public void setOperator(String operator) {
		this.operator = operator;
	}

	/**
	 * @param instanceStarter
	 *            the instanceStarter to set
	 */
	public void setInstanceStarter(String instanceStarter) {
		this.instanceStarter = instanceStarter;
	}

	/**
	 * @param outerSystem
	 *            the outerSystem to set
	 */
	public void setOuterSystem(String outerSystem) {
		this.outerSystem = outerSystem;
	}

	/**
	 * @param opinionType
	 *            the opinionType to set
	 */
	public void setOpinionType(EnumProcessOperateOpinionType opinionType) {
		this.opinionType = opinionType;
	}

	/**
	 * @param opinionString
	 *            the opinionString to set
	 */
	public void setOpinionString(String opinionString) {
		this.opinionString = opinionString;
	}

	/**
	 * @param nodeName
	 *            the nodeName to set
	 */
	public void setNodeName(String nodeName) {
		this.nodeName = nodeName;
	}

	/**
	 * @param nodeDesc
	 *            the nodeDesc to set
	 */
	public void setNodeDesc(String nodeDesc) {
		this.nodeDesc = nodeDesc;
	}

	/**
	 * @param processDefinitionId
	 *            the processDefinitionId to set
	 */
	public void setProcessDefinitionId(String processDefinitionId) {
		this.processDefinitionId = processDefinitionId;
	}

	/**
	 * @param processDesc
	 *            the processDesc to set
	 */
	public void setProcessDesc(String processDesc) {
		this.processDesc = processDesc;
	}

	/**
	 * @return the version
	 */
	public Integer getVersion() {
		return version;
	}

	/**
	 * @param version
	 *            the version to set
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}

	/**
	 * @return the processDefinitionName
	 */
	public String getProcessDefinitionName() {
		return processDefinitionName;
	}

	/**
	 * @param processDefinitionName
	 *            the processDefinitionName to set
	 */
	public void setProcessDefinitionName(String processDefinitionName) {
		this.processDefinitionName = processDefinitionName;
	}

	/**
	 * @return the outCome
	 */
	public String getOutCome() {
		return outCome;
	}

	/**
	 * @param outCome
	 *            the outCome to set
	 */
	public void setOutCome(String outCome) {
		this.outCome = outCome;
	}

	/**
	 * @return the attachements
	 */
	public List<Attachement> getAttachements() {
		return attachements;
	}

	/**
	 * @param attachements
	 *            the attachements to set
	 */
	public void setAttachements(List<Attachement> attachements) {
		this.attachements = attachements;
	}

	/**
	 * @return the operatorName
	 */
	public String getOperatorName() {
		return operatorName;
	}

	/**
	 * @param operatorName
	 *            the operatorName to set
	 */
	public void setOperatorName(String operatorName) {
		this.operatorName = operatorName;
	}
}
